package com.letsiot.applications.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.letsiot.applications.entity.SysOperatorLog;
import com.letsiot.applications.entity.enums.OperatorType;
import com.letsiot.applications.entity.vo.ContainerOpeartionTableVO;
import com.letsiot.applications.entity.vo.ResgistryOpeartionTableVO;
import com.letsiot.applications.service.SysOperatorLogService;

@RestController
@RequestMapping("/operatorLog")
@Validated
public class SysOperatorLogController {

    @Autowired
    private SysOperatorLogService sysOperatorLogService;

    @PostMapping("save")
    public int save(@RequestBody SysOperatorLog entity) {
        return sysOperatorLogService.save(entity);
    }

    @DeleteMapping("delete")
    public int delete(Long id) {
        return sysOperatorLogService.delete(id);
    }

    @PutMapping("update")
    public int update(@RequestBody SysOperatorLog entity) {
        return sysOperatorLogService.update(entity);
    }

    @GetMapping("findById")
    public SysOperatorLog findById(Long id) {
        return sysOperatorLogService.findById(id);
    }

    @GetMapping("getAll")
    public List<SysOperatorLog> getAll() {
        return sysOperatorLogService.getAll();
    }

    @GetMapping("getOperatorLog")
    public Page<SysOperatorLog> getOperatorLog(Date startDate, Date endDate, OperatorType operatorType, Long userId,
            int page, int size) {
        Pageable pageable = PageRequest.of(page, size);
        return sysOperatorLogService.getOperatorLog(startDate, endDate, operatorType, userId, pageable);
    }

    @GetMapping("/registryOperationPage")
    public Page<ResgistryOpeartionTableVO> registryOperationPage(int page, int size, String messageType,
            String operationLogOrOperationName, Date startDate, String endDate, String remark) {
        Pageable pageable = PageRequest.of(page, size);
        return sysOperatorLogService.registryOperationPage(pageable, messageType, operationLogOrOperationName,
                startDate, endDate, remark);
    }

    @GetMapping("/containerOperationPage")
    public Page<ContainerOpeartionTableVO> containerOperationPage(int page, int size,
            String operationLogOrOperationName, Date startDate, String endDate, String remark) {
        Pageable pageable = PageRequest.of(page, size);
        return sysOperatorLogService.containerOperationPage(pageable, operationLogOrOperationName, startDate, endDate,
                remark);
    }
}
